import path from "path";
import Cookie from "js-cookie";
const resolve = (pagePath) => path.resolve(process.cwd(), `./${pagePath}`);
const getRoutes = [
  {
    path: "/",
    component: resolve("/layouts/index.vue"),
    children: [
      {
        path: "/",
        redirect: "/home",
      },
      {
        path: "/home", // 默认子路由
        name: "home",
        component: resolve("pages/home/"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/login",
        name: "login",
        component: resolve("pages/login/"),
      },
      {
        path: "/artwork",
        name: "artwork",
        component: resolve("pages/artwork"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/artwork/desc",
        name: "artWorkDesc",
        component: resolve("pages/artwork/desc"),
      },
      {
        path: "/artist",
        name: "artist",
        component: resolve("pages/artist"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/onLineVideo",
        name: "onLineVideo",
        component: resolve("pages/onlinevideo"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/onLineVideo/desc",
        name: "onLineVideoDesc",
        component: resolve("pages/onlinevideo/desc"),
      },
      {
        path: "/artShop",
        name: "artShop",
        component: resolve("pages/artshop"),
        meta: {
          title: "数字展览",
          banner_list: [],
          threeBanner: [],
          vrBanner: [],
          boutiqueBanner: [],
          artBanner: []
        },
      },
      {
        path: "/artShop/desc",
        name: "artShopDesc",
        component: resolve("pages/artshop/desc"),
      },
      {
        path: "/artShop/showRoom",
        name: "showRoom",
        component: resolve("pages/artshop/showRoom"),
      },
      {
        path: "/artShop/showHall",
        name: "showHall",
        component: resolve("pages/artshop/showHall.vue"),
      },
      {
        path: "/artShop/showHall/showHallDesc",
        name: "showHallDesc",
        component: resolve("pages/artshop/showHallDesc.vue"),
      },
      {
        path: "/artShop/artHall",
        name: "artHall",
        component: resolve("pages/artshop/artHall.vue"),
      },
      {
        path: "/dynamic",
        name: "dynamic",
        component: resolve("pages/dynamic"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/about",
        name: "about",
        component: resolve("pages/about/"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/about/module6Desc",
        name: "module6Desc",
        component: resolve("pages/about/module6Desc"),
        meta: {
          title: "",
          banner_list: []
        },
      },
      {
        path: "/register", // 注册页
        name: "register",
        component: resolve("pages/register/"),
      },
      {
        path: "/policy/:type", // 隐私政策等页
        name: "policy",
        component: resolve("pages/policy/"),
      },
      {
        path: "/search", // 搜索页
        name: "search",
        component: resolve("pages/search"),
      },
      {
        path: "/forgetPassword",
        name: "forgetPassword",
        component: resolve("pages/forgetPassword"),
      },
      {
        path: "/personal",
        name: "personal",
        component: resolve("pages/personal"),
      },
      {
        path: "/editPersonalHome/personalInfo",
        name: "personalInfo",
        component: resolve("pages/editPersonalHome/personalInfo"),
      },
      {
        path: "/editPersonalHome",
        name: "editPersonalHome",
        component: resolve("pages/editPersonalHome/"),
      },
      {
        path: "/editPersonalHome/uploadWorks",
        name: "uploadWorks",
        component: resolve("pages/editPersonalHome/uploadWorks"),
      },
      {
        path: "/editPersonalHome/uploadVideos",
        name: "uploadVideos",
        component: resolve("pages/editPersonalHome/uploadVideos"),
      },
      {
        path: "/editPersonalHome/uploadActivity",
        name: "uploadActivity",
        component: resolve("pages/editPersonalHome/uoloadActivity"),
      },
      {
        path: "/applyArtist",
        name: "applyArtist",
        component: resolve("pages/applyArtist"),
      },
      {
        path: "/videoDesc",
        name: "videoDesc",
        component: resolve("pages/videoDesc"),
      },
      // 收藏、关注、消息
      {
        path: "/followMessage",
        name: "followMessage",
        component: resolve("pages/followMessage"),
      },
      // 专题活动详情页
      {
        path: "/dynamic/activityDesc",
        name: "activityDesc",
        component: resolve("pages/dynamic/activityDesc/"),
      },
      {
        path: "/dynamic/articleDesc",
        name: "articleDesc",
        component: resolve("pages/dynamic/articleDesc"),
      }
    ],
  },
  {
    path: "/404",
    name: "/404",
    component: resolve("pages/error"),
  },
  {
    path: "*",
    redirect: "/404",
    component: resolve("pages/error"),
    chunkName: "pages/index",
  },
];

const state = () => ({
  router: getRoutes,
  activeRouter: Cookie.get("activeRouter") || "/home",
  isPc: Cookie.get("isPc"),
});

const mutations = {
  setActiveRoute(state, payload) {
    state.activeRouter = payload.activeRouter;
    Cookie.set("activeRouter", payload.activeRouter);
  },
  setIspc(state, payload) {
    state.isPc = payload.isPc;
    Cookie.set("isPc", payload.isPc);
  },
  setRoute(state, payload) {
    payload.forEach(item => {
      state.router[0].children.forEach(ele => {
        if (ele?.path == item.path) {
          ele.meta.banner_list = item.banner_list
          ele.meta.title = item.menu_name
        }
        if (item.menu_name === 'VR展厅' && ele?.meta?.title === '数字展馆') {
          ele.meta.vrBanner = item.banner_list
        }
        if (item.menu_name === '3D展厅' && ele?.meta?.title === '数字展馆') {
          ele.meta.threeBanner = item.banner_list
        }
        if (item.menu_name === '艺术展厅' && ele?.meta?.title === '数字展馆') {
          ele.meta.artBanner = item.banner_list
        }
        if (item.menu_name === '精品展厅' && ele?.meta?.title === '数字展馆') {
          ele.meta.boutiqueBanner = item.banner_list
        }
      })
    })
    console.log('state', state.router[0].children)
  }
};

export default {
  state,
  mutations,
};
